<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
</head>
<style>
</style>
<body id="body" style="padding-bottom: 90px; background-color: #ECF0F5;">
	<div class="modal-content">
		<div class="modal-body">
			<div class="input-group">
				<span class="input-group-addon">所属小区：</span> <input type="text" class="form-control" disabled="disabled" value="${sessionScope.communityName}">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">工单类别：</span> <select id="categoryId" class="form-control">
					<option value="">请选择...</option>
				</select>
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">标题：</span> <input type="text" class="form-control" id="s1">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">位置：</span> <input type="text" class="form-control" id="addr">
			</div>
			<br />
			<div class="form-group">
				<label for="mien_pic" class="control-label">工单内容：</label>
				<textarea class="form-control" style="width: 100%; height: 300px;" id="column1_textarea" name="kindEditor_content"></textarea>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>

<!-- kindeditor 编辑器 -->
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script>
	var lock = false;
	var id = "${map['id']}";
	var index = parent.layer.getFrameIndex(window.name);
	var editor;
	// 	var userId = "";
	var options = {
		items : [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
				'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
				'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
				'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], //配置kindeditor编辑器的工具栏菜单项
		cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
		allowFileManager : true,
		filterMode : true, //是否启用过滤模式(编辑文本框中是否可以出现控件显示)
		htmlTags : {
			span : [ '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height' ],
			font : [ 'id', 'class', 'color', 'size', 'face', '.background-color' ],
			a : [ 'id', 'class', 'href', 'target', 'name' ],
			embed : [ 'id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess' ],
			img : [ 'id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border' ],
			'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight',
					'.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' ],
			pre : [ 'id', 'class' ],
			hr : [ 'id', 'class', '.page-break-after' ],
			'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : [ 'id', 'class' ],
			iframe : [ 'id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height' ]
		},
		allowFileManager : true,
		allowUpload : true, //允许上传图片
		imageUploadJson : '/saveImg', //服务端上传图片处理URI
		uploadJson : '${pageContext.request.contextPath}/upload_img', //上传
		// 		fileManagerJson : '${pageContext.request.contextPath}/mien_file_manager.do', // 文件管理
		resizeType : 0,//使其不可以拖动 
		afterCreate : function() {
		},
		afterBlur : function() {
			this.sync();
		}
	}
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="kindEditor_content"]', options);
	});

	$(function() {
		$.ajax({
			url : "${pageContext.request.contextPath}/selectPropertyTypeByAll",
			type : "post",
			dataType : "json",
			success : function(map) {
				var list = map['list'];
				
				var html = "<option value=''>请选择...</option>";
				for (var i = 0; i < list.length; i++) {
					html += "<option value='"+list[i].id+"'>" + list[i].name + "</option>";
				}
				$("#categoryId").html(html);
				if (id != '') {
					$.ajax({
						url : "${pageContext.request.contextPath}/selectPropertyWorkorderById",
						type : "post",
						data : {
							id : id
						},
						dataType : "json",
						success : function(map) {
							var workorder = map['workorder'];
							$("#categoryId").val(workorder.categoryId);
							$("#addr").val(workorder.addr);
							$("#s1").val(workorder.s1);
							$("#column1_textarea").val(workorder.content);
							editor.html(workorder.content);
						}
					});
				}
			}
		});
	});

	//添加或修改
	function insertPropertyWorkorder() {
		lock = true;
		var categoryId = $("#categoryId").val();
		var addr = $("#addr").val();
		var s1 = $("#s1").val();
		var column1_textarea = $("#column1_textarea").val();
		if (categoryId === '' || column1_textarea === '' || addr === '' || s1 === '') {
			layer.alert("请填写标题，内容!");
			lock = false;
			return;
		}
		$.ajax({
			url : '${pageContext.request.contextPath}/insertPropertyWorkorder',
			type : "post",
			data : {
				id : id,
				categoryId : categoryId,
				addr : addr,
				content : column1_textarea,
				s1 : s1
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						parent.query();
						parent.layer.close(index);
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
					lock = false;
				}
			}
		});
	}

	function insert() {
		if (!lock) {
			insertPropertyWorkorder();
		}
	}
</script>
</html>
